using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACME.Northwind.DataTransfer;
using ACME.Northwind.Service.Interfaces;
using ACME.Northwind.MockProxy.EventArgs;

namespace ACME.Northwind.MockProxy
{
	/// <summary>
	/// The service implementation for Category object
	/// </summary>
	public partial class CategoryService : ICategoryService
	{
		#region ICategoryService Members

		/// <summary>
		/// Run the mock for the select by the primary key
		/// </summary>
		public CategoryDTO SelectByPrimaryKey(int categoryid)
		{
			CategoryPrimaryKeyEventArgs eventArgs = new CategoryPrimaryKeyEventArgs(categoryid);
			this.OnMockCategorySelectByPrimaryKey(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for select all
		/// </summary>
		public List<CategoryDTO> RunSelect()
		{
			CategoryRunSelectEventArgs eventArgs = new CategoryRunSelectEventArgs();
			this.OnMockCategoryRunSelect(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for select with LINQ
		/// </summary>
		public List<CategoryDTO> RunSelect(string linq)
		{
			CategoryRunSelectLINQEventArgs eventArgs = new CategoryRunSelectLINQEventArgs(linq);
			this.OnMockCategoryRunSelectLINQ(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Run the mock for paged select
		/// </summary>
		public PagedQueryResults<CategoryDTO> RunSelect(int pageIndex, int pageSize, bool ascending, string sortColumn, string linq)
		{
			CategoryRunSelectPagedEventArgs eventArgs = new CategoryRunSelectPagedEventArgs(pageIndex, pageSize, ascending, sortColumn, linq);
			this.OnMockCategoryRunSelectPaged(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Return a list of related Product objects
		/// </summary>
		public List<ProductDTO> GetProductList(CategoryDTO item)
		{
			CategoryDTOEventArgs eventArgs = new CategoryDTOEventArgs(item);
			this.OnMockGetProductList(eventArgs);
			List<ProductDTO> retval = new List<ProductDTO>();
			retval.AddRange(eventArgs.ReturnDTOList.Select(x => (ProductDTO)x));
			return retval;
		}

		/// <summary>
		/// Persists a single item
		/// </summary>
		public bool Persist(CategoryDTO dto)
		{
			CategoryPersistEventArgs eventArgs = new CategoryPersistEventArgs(dto);
			this.OnMockCategoryPersist(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Persists a list
		/// </summary>
		public bool Persist(List<CategoryDTO> list)
		{
			CategoryPersistEventArgs eventArgs = new CategoryPersistEventArgs(list);
			this.OnMockCategoryPersist(eventArgs);
			return eventArgs.ReturnValue;
		}

		/// <summary>
		/// Delete a single item
		/// </summary>
		public bool Delete(CategoryDTO dto)
		{
			CategoryDeleteEventArgs eventArgs = new CategoryDeleteEventArgs(dto);
			this.OnMockCategoryDelete(eventArgs);
			return eventArgs.ReturnValue;
		}

		#endregion

		#region Category Events

		partial void GetSelectByPrimaryKey();

		/// <summary>
		/// The event for the SelectByPrimaryKey method
		/// </summary>
		public event EventHandler<CategoryPrimaryKeyEventArgs> MockCategorySelectByPrimaryKey;

		/// <summary>
		/// Raises the OnMockRegistrationCodeSelectByPrimaryKey event
		/// </summary>
		protected virtual void OnMockCategorySelectByPrimaryKey(CategoryPrimaryKeyEventArgs e)
		{
			if (this.MockCategorySelectByPrimaryKey != null)
				this.MockCategorySelectByPrimaryKey(this, e);
		}

		/// <summary>
		/// The event for the RunSelect method
		/// </summary>
		public event EventHandler<CategoryRunSelectEventArgs> MockCategoryRunSelect;

		/// <summary>
		/// Raises the OnMockRunSelect event
		/// </summary>
		protected virtual void OnMockCategoryRunSelect(CategoryRunSelectEventArgs e)
		{
			if (this.MockCategoryRunSelect != null)
				this.MockCategoryRunSelect(this, e);
		}

		/// <summary>
		/// The event for the RunSelectLINQ method
		/// </summary>
		public event EventHandler<CategoryRunSelectLINQEventArgs> MockCategoryRunSelectLINQ;

		/// <summary>
		/// The event for the OnMockRunSelectLINQ method
		/// </summary>
		protected virtual void OnMockCategoryRunSelectLINQ(CategoryRunSelectLINQEventArgs e)
		{
			if (this.MockCategoryRunSelectLINQ != null)
				this.MockCategoryRunSelectLINQ(this, e);
		}

		/// <summary>
		/// The event for the RunSelectPaged method
		/// </summary>
		public event EventHandler<CategoryRunSelectPagedEventArgs> MockCategoryRunSelectPaged;

		/// <summary>
		/// The event for the OnMockRunSelectPaged method
		/// </summary>
		protected virtual void OnMockCategoryRunSelectPaged(CategoryRunSelectPagedEventArgs e)
		{
			if (this.MockCategoryRunSelectPaged != null)
				this.MockCategoryRunSelectPaged(this, e);
		}

		/// <summary>
		/// The event for the GetProductList method
		/// </summary>
		public event EventHandler<CategoryDTOEventArgs> MockGetProductList;

		/// <summary>
		/// The event for the OnMockGetProductList method
		/// </summary>
		protected virtual void OnMockGetProductList(CategoryDTOEventArgs e)
		{
			if (this.MockGetProductList != null)
				this.MockGetProductList(this, e);
		}

		/// <summary>
		/// The event for the Persist method
		/// </summary>
		public event EventHandler<CategoryPersistEventArgs> MockCategoryPersist;

		/// <summary>
		/// Raises the OnMockPersist event
		/// </summary>
		protected virtual void OnMockCategoryPersist(CategoryPersistEventArgs e)
		{
			if (this.MockCategoryPersist != null)
				this.MockCategoryPersist(this, e);
		}

		/// <summary>
		/// The event for the Delete method
		/// </summary>
		public event EventHandler<CategoryDeleteEventArgs> MockCategoryDelete;

		/// <summary>
		/// Raises the OnMockDelete event
		/// </summary>
		protected virtual void OnMockCategoryDelete(CategoryDeleteEventArgs e)
		{
			if (this.MockCategoryDelete != null)
				this.MockCategoryDelete(this, e);
		}

		#endregion

	}
}
